<!DOCTYPE html>
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
  <meta name="description" content="刘清政">
  <meta name="keyword" content="hexo-theme">
  
    <link rel="shortcut icon" href="/css/images/logo.png">
  
  <title>
    
      python/路飞项目/6-课程模块/2-课程主页之课程表分析 | Justin-刘清政的博客
    
  </title>
  <link href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
  <link href="//cdnjs.cloudflare.com/ajax/libs/nprogress/0.2.0/nprogress.min.css" rel="stylesheet">
  <link href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/tomorrow.min.css" rel="stylesheet">
  
<link rel="stylesheet" href="/css/style.css">

  
    
<link rel="stylesheet" href="/css/plugins/gitment.css">

  
  <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/geopattern/1.2.3/js/geopattern.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/nprogress/0.2.0/nprogress.min.js"></script>
  
    
<script src="/js/qrious.js"></script>

  
  
    
<script src="/js/gitment.js"></script>

  
  

  
<meta name="generator" content="Hexo 4.2.0"></head>
<div class="wechat-share">
  <img src="/css/images/logo.png" />
</div>

  <body>
    <header class="header fixed-header">
  <div class="header-container">
    <a class="home-link" href="/">
      <div class="logo"></div>
      <span>Justin-刘清政的博客</span>
    </a>
    <ul class="right-list">
      
        <li class="list-item">
          
            <a href="/" class="item-link">主页</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/tags/" class="item-link">标签</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/archives/" class="item-link">归档</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/about/" class="item-link">关于我</a>
          
        </li>
      
    </ul>
    <div class="menu">
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </div>
    <div class="menu-mask">
      <ul class="menu-list">
        
          <li class="menu-item">
            
              <a href="/" class="menu-link">主页</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/tags/" class="menu-link">标签</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/archives/" class="menu-link">归档</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/about/" class="menu-link">关于我</a>
            
          </li>
        
      </ul>
    </div>
  </div>
</header>

    <div id="article-banner">
  <h2>python/路飞项目/6-课程模块/2-课程主页之课程表分析</h2>



  <p class="post-date">2020-01-10</p>
    <!-- 不蒜子统计 -->
    <span id="busuanzi_container_page_pv" style='display:none' class="">
        <i class="icon-smile icon"></i> 阅读数：<span id="busuanzi_value_page_pv"></span>次
    </span>
  <div class="arrow-down">
    <a href="javascript:;"></a>
  </div>
</div>
<main class="app-body flex-box">
  <!-- Article START -->
  <article class="post-article">
    <section class="markdown-content"><h2 id="课程表分析"><a href="#课程表分析" class="headerlink" title="课程表分析"></a>课程表分析</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Course</span><span class="params">(models.Model)</span>:</span></span><br><span class="line">    name = models.CharField(max_length=<span class="number">64</span>)</span><br><span class="line">    title = models.CharField(max_length=<span class="number">64</span>)</span><br><span class="line">    students = models.IntegerField(default=<span class="number">0</span>)</span><br><span class="line">    level = models.IntegerField(choices=((<span class="number">0</span>, <span class="string">'入门'</span>), (<span class="number">1</span>, <span class="string">'进阶'</span>)), default=<span class="number">0</span>)</span><br><span class="line">    time = models.IntegerField(default=<span class="number">0</span>)</span><br><span class="line">    detail = models.TextField()  <span class="comment"># 可以关联详情表</span></span><br><span class="line">    type = models.IntegerField(choices=((<span class="number">0</span>, <span class="string">'Python'</span>), (<span class="number">1</span>, <span class="string">'Linux'</span>)), default=<span class="number">0</span>)</span><br><span class="line">    is_show = models.BooleanField(default=<span class="literal">False</span>)</span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Meta</span>:</span></span><br><span class="line">        abstract = <span class="literal">True</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 免费课</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">FreeCourse</span><span class="params">(Course)</span>:</span></span><br><span class="line">    image = models.ImageField(upload_to=<span class="string">'course/free'</span>)</span><br><span class="line">    attachment = models.FileField(upload_to=<span class="string">'attachment'</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 实战课</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">ActualCourse</span><span class="params">(Course)</span>:</span></span><br><span class="line">    image = models.ImageField(upload_to=<span class="string">'course/actual'</span>)</span><br><span class="line">    price = models.DecimalField(max_digits=<span class="number">7</span>, decimal_places=<span class="number">2</span>)</span><br><span class="line">    cost = models.DecimalField(max_digits=<span class="number">7</span>, decimal_places=<span class="number">2</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 轻课</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">LightCourse</span><span class="params">(Course)</span>:</span></span><br><span class="line">    image = models.ImageField(upload_to=<span class="string">'course/light'</span>)</span><br><span class="line">    price = models.DecimalField(max_digits=<span class="number">7</span>, decimal_places=<span class="number">2</span>)</span><br><span class="line">    cost = models.DecimalField(max_digits=<span class="number">7</span>, decimal_places=<span class="number">2</span>)</span><br><span class="line">    period = models.IntegerField(verbose_name=<span class="string">'学习建议周期(month)'</span>, default=<span class="number">0</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 评论表：分三个表、(id，ctx，date，user_id，free_course_id, comment_id)</span></span><br><span class="line"><span class="comment"># 老师表：在课程表建立多对一外键</span></span><br><span class="line"><span class="comment"># 章节表：在章节表建立多对一外键关联课程</span></span><br><span class="line"><span class="comment"># 课时表：在课时表建立多对一外键关联章节</span></span><br></pre></td></tr></table></figure>







<h2 id="免费课案例"><a href="#免费课案例" class="headerlink" title="免费课案例"></a>免费课案例</h2><h5 id="创建models：course-models-py"><a href="#创建models：course-models-py" class="headerlink" title="创建models：course/models.py"></a>创建models：course/models.py</h5><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">CourseCategory</span><span class="params">(BaseModel)</span>:</span></span><br><span class="line">    <span class="string">"""分类"""</span></span><br><span class="line">    name = models.CharField(max_length=<span class="number">64</span>, unique=<span class="literal">True</span>, verbose_name=<span class="string">"分类名称"</span>)</span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Meta</span>:</span></span><br><span class="line">        db_table = <span class="string">"luffy_course_category"</span></span><br><span class="line">        verbose_name = <span class="string">"分类"</span></span><br><span class="line">        verbose_name_plural = verbose_name</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__str__</span><span class="params">(self)</span>:</span></span><br><span class="line">        <span class="keyword">return</span> <span class="string">"%s"</span> % self.name</span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Course</span><span class="params">(BaseModel)</span>:</span></span><br><span class="line">    <span class="string">"""课程"""</span></span><br><span class="line">    course_type = (</span><br><span class="line">        (<span class="number">0</span>, <span class="string">'付费'</span>),</span><br><span class="line">        (<span class="number">1</span>, <span class="string">'VIP专享'</span>),</span><br><span class="line">        (<span class="number">2</span>, <span class="string">'学位课程'</span>)</span><br><span class="line">    )</span><br><span class="line">    level_choices = (</span><br><span class="line">        (<span class="number">0</span>, <span class="string">'初级'</span>),</span><br><span class="line">        (<span class="number">1</span>, <span class="string">'中级'</span>),</span><br><span class="line">        (<span class="number">2</span>, <span class="string">'高级'</span>),</span><br><span class="line">    )</span><br><span class="line">    status_choices = (</span><br><span class="line">        (<span class="number">0</span>, <span class="string">'上线'</span>),</span><br><span class="line">        (<span class="number">1</span>, <span class="string">'下线'</span>),</span><br><span class="line">        (<span class="number">2</span>, <span class="string">'预上线'</span>),</span><br><span class="line">    )</span><br><span class="line">    name = models.CharField(max_length=<span class="number">128</span>, verbose_name=<span class="string">"课程名称"</span>)</span><br><span class="line">    course_img = models.ImageField(upload_to=<span class="string">"courses"</span>, max_length=<span class="number">255</span>, verbose_name=<span class="string">"封面图片"</span>, blank=<span class="literal">True</span>, null=<span class="literal">True</span>)</span><br><span class="line">    course_type = models.SmallIntegerField(choices=course_type, default=<span class="number">0</span>, verbose_name=<span class="string">"付费类型"</span>)</span><br><span class="line">    <span class="comment"># 使用这个字段的原因</span></span><br><span class="line">    brief = models.TextField(max_length=<span class="number">2048</span>, verbose_name=<span class="string">"详情介绍"</span>, null=<span class="literal">True</span>, blank=<span class="literal">True</span>)</span><br><span class="line">    level = models.SmallIntegerField(choices=level_choices, default=<span class="number">0</span>, verbose_name=<span class="string">"难度等级"</span>)</span><br><span class="line">    pub_date = models.DateField(verbose_name=<span class="string">"发布日期"</span>, auto_now_add=<span class="literal">True</span>)</span><br><span class="line">    period = models.IntegerField(verbose_name=<span class="string">"建议学习周期(day)"</span>, default=<span class="number">7</span>)</span><br><span class="line">    attachment_path = models.FileField(upload_to=<span class="string">"attachment"</span>, max_length=<span class="number">128</span>, verbose_name=<span class="string">"课件路径"</span>, blank=<span class="literal">True</span>,</span><br><span class="line">                                       null=<span class="literal">True</span>)</span><br><span class="line">    status = models.SmallIntegerField(choices=status_choices, default=<span class="number">0</span>, verbose_name=<span class="string">"课程状态"</span>)</span><br><span class="line">    course_category = models.ForeignKey(<span class="string">"CourseCategory"</span>, on_delete=models.SET_NULL, db_constraint=<span class="literal">False</span>, null=<span class="literal">True</span>, blank=<span class="literal">True</span>,</span><br><span class="line">                                        verbose_name=<span class="string">"课程分类"</span>)</span><br><span class="line">    students = models.IntegerField(verbose_name=<span class="string">"学习人数"</span>, default=<span class="number">0</span>)</span><br><span class="line">    sections = models.IntegerField(verbose_name=<span class="string">"总课时数量"</span>, default=<span class="number">0</span>)</span><br><span class="line">    pub_sections = models.IntegerField(verbose_name=<span class="string">"课时更新数量"</span>, default=<span class="number">0</span>)</span><br><span class="line">    price = models.DecimalField(max_digits=<span class="number">6</span>, decimal_places=<span class="number">2</span>, verbose_name=<span class="string">"课程原价"</span>, default=<span class="number">0</span>)</span><br><span class="line">    teacher = models.ForeignKey(<span class="string">"Teacher"</span>, on_delete=models.DO_NOTHING, null=<span class="literal">True</span>, blank=<span class="literal">True</span>, verbose_name=<span class="string">"授课老师"</span>)</span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Meta</span>:</span></span><br><span class="line">        db_table = <span class="string">"luffy_course"</span></span><br><span class="line">        verbose_name = <span class="string">"课程"</span></span><br><span class="line">        verbose_name_plural = <span class="string">"课程"</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__str__</span><span class="params">(self)</span>:</span></span><br><span class="line">        <span class="keyword">return</span> <span class="string">"%s"</span> % self.name</span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Teacher</span><span class="params">(BaseModel)</span>:</span></span><br><span class="line">    <span class="string">"""导师"""</span></span><br><span class="line">    role_choices = (</span><br><span class="line">        (<span class="number">0</span>, <span class="string">'讲师'</span>),</span><br><span class="line">        (<span class="number">1</span>, <span class="string">'导师'</span>),</span><br><span class="line">        (<span class="number">2</span>, <span class="string">'班主任'</span>),</span><br><span class="line">    )</span><br><span class="line">    name = models.CharField(max_length=<span class="number">32</span>, verbose_name=<span class="string">"导师名"</span>)</span><br><span class="line">    role = models.SmallIntegerField(choices=role_choices, default=<span class="number">0</span>, verbose_name=<span class="string">"导师身份"</span>)</span><br><span class="line">    title = models.CharField(max_length=<span class="number">64</span>, verbose_name=<span class="string">"职位、职称"</span>)</span><br><span class="line">    signature = models.CharField(max_length=<span class="number">255</span>, verbose_name=<span class="string">"导师签名"</span>, help_text=<span class="string">"导师签名"</span>, blank=<span class="literal">True</span>, null=<span class="literal">True</span>)</span><br><span class="line">    image = models.ImageField(upload_to=<span class="string">"teacher"</span>, null=<span class="literal">True</span>, verbose_name=<span class="string">"导师封面"</span>)</span><br><span class="line">    brief = models.TextField(max_length=<span class="number">1024</span>, verbose_name=<span class="string">"导师描述"</span>)</span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Meta</span>:</span></span><br><span class="line">        db_table = <span class="string">"luffy_teacher"</span></span><br><span class="line">        verbose_name = <span class="string">"导师"</span></span><br><span class="line">        verbose_name_plural = verbose_name</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__str__</span><span class="params">(self)</span>:</span></span><br><span class="line">        <span class="keyword">return</span> <span class="string">"%s"</span> % self.name</span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">CourseChapter</span><span class="params">(BaseModel)</span>:</span></span><br><span class="line">    <span class="string">"""章节"""</span></span><br><span class="line">    course = models.ForeignKey(<span class="string">"Course"</span>, related_name=<span class="string">'coursechapters'</span>, on_delete=models.CASCADE, verbose_name=<span class="string">"课程名称"</span>)</span><br><span class="line">    chapter = models.SmallIntegerField(verbose_name=<span class="string">"第几章"</span>, default=<span class="number">1</span>)</span><br><span class="line">    name = models.CharField(max_length=<span class="number">128</span>, verbose_name=<span class="string">"章节标题"</span>)</span><br><span class="line">    summary = models.TextField(verbose_name=<span class="string">"章节介绍"</span>, blank=<span class="literal">True</span>, null=<span class="literal">True</span>)</span><br><span class="line">    pub_date = models.DateField(verbose_name=<span class="string">"发布日期"</span>, auto_now_add=<span class="literal">True</span>)</span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Meta</span>:</span></span><br><span class="line">        db_table = <span class="string">"luffy_course_chapter"</span></span><br><span class="line">        verbose_name = <span class="string">"章节"</span></span><br><span class="line">        verbose_name_plural = verbose_name</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__str__</span><span class="params">(self)</span>:</span></span><br><span class="line">        <span class="keyword">return</span> <span class="string">"%s:(第%s章)%s"</span> % (self.course, self.chapter, self.name)</span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">CourseSection</span><span class="params">(BaseModel)</span>:</span></span><br><span class="line">    <span class="string">"""课时"""</span></span><br><span class="line">    section_type_choices = (</span><br><span class="line">        (<span class="number">0</span>, <span class="string">'文档'</span>),</span><br><span class="line">        (<span class="number">1</span>, <span class="string">'练习'</span>),</span><br><span class="line">        (<span class="number">2</span>, <span class="string">'视频'</span>)</span><br><span class="line">    )</span><br><span class="line">    chapter = models.ForeignKey(<span class="string">"CourseChapter"</span>, related_name=<span class="string">'coursesections'</span>, on_delete=models.CASCADE,</span><br><span class="line">                                verbose_name=<span class="string">"课程章节"</span>)</span><br><span class="line">    name = models.CharField(max_length=<span class="number">128</span>, verbose_name=<span class="string">"课时标题"</span>)</span><br><span class="line">    orders = models.PositiveSmallIntegerField(verbose_name=<span class="string">"课时排序"</span>)</span><br><span class="line">    section_type = models.SmallIntegerField(default=<span class="number">2</span>, choices=section_type_choices, verbose_name=<span class="string">"课时种类"</span>)</span><br><span class="line">    section_link = models.CharField(max_length=<span class="number">255</span>, blank=<span class="literal">True</span>, null=<span class="literal">True</span>, verbose_name=<span class="string">"课时链接"</span>,</span><br><span class="line">                                    help_text=<span class="string">"若是video，填vid,若是文档，填link"</span>)</span><br><span class="line">    duration = models.CharField(verbose_name=<span class="string">"视频时长"</span>, blank=<span class="literal">True</span>, null=<span class="literal">True</span>, max_length=<span class="number">32</span>)  <span class="comment"># 仅在前端展示使用</span></span><br><span class="line">    pub_date = models.DateTimeField(verbose_name=<span class="string">"发布时间"</span>, auto_now_add=<span class="literal">True</span>)</span><br><span class="line">    free_trail = models.BooleanField(verbose_name=<span class="string">"是否可试看"</span>, default=<span class="literal">False</span>)</span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Meta</span>:</span></span><br><span class="line">        db_table = <span class="string">"luffy_course_Section"</span></span><br><span class="line">        verbose_name = <span class="string">"课时"</span></span><br><span class="line">        verbose_name_plural = verbose_name</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__str__</span><span class="params">(self)</span>:</span></span><br><span class="line">        <span class="keyword">return</span> <span class="string">"%s-%s"</span> % (self.chapter, self.name)</span><br></pre></td></tr></table></figure>

<h5 id="注册models：course-adminx-py"><a href="#注册models：course-adminx-py" class="headerlink" title="注册models：course/adminx.py"></a>注册models：course/adminx.py</h5><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> xadmin</span><br><span class="line"><span class="keyword">from</span> . <span class="keyword">import</span> models</span><br><span class="line">xadmin.site.register(models.CourseCategory)</span><br><span class="line">xadmin.site.register(models.Course)</span><br><span class="line">xadmin.site.register(models.Teacher)</span><br><span class="line">xadmin.site.register(models.CourseChapter)</span><br><span class="line">xadmin.site.register(models.CourseSection)</span><br></pre></td></tr></table></figure>

<h5 id="数据库迁移"><a href="#数据库迁移" class="headerlink" title="数据库迁移"></a>数据库迁移</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&gt;: python manage.py makemigrations</span><br><span class="line">&gt;: python manage.py migrate</span><br></pre></td></tr></table></figure>








</section>
    <!-- Tags START -->
    
    <!-- Tags END -->
    <!-- NAV START -->
    
  <div class="nav-container">
    <!-- reverse left and right to put prev and next in a more logic postition -->
    
      <a class="nav-left" href="/db/Elasticsearch%E7%B3%BB%E5%88%97/19-Elasticsearch%E4%B9%8B%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6/">
        <span class="nav-arrow">← </span>
        
          db/Elasticsearch系列/19-Elasticsearch之配置文件
        
      </a>
    
    
      <a class="nav-right" href="/python/%E8%B7%AF%E9%A3%9E%E9%A1%B9%E7%9B%AE/6-%E8%AF%BE%E7%A8%8B%E6%A8%A1%E5%9D%97/1-%E8%AF%BE%E7%A8%8B%E9%A1%B5%E9%A1%B5%E9%9D%A2/">
        
          python/路飞项目/6-课程模块/1-课程页页面
        
        <span class="nav-arrow"> →</span>
      </a>
    
  </div>

    <!-- NAV END -->
    <!-- 打赏 START -->
    
      <div class="money-like">
        <div class="reward-btn">
          赏
          <span class="money-code">
            <span class="alipay-code">
              <div class="code-image"></div>
              <b>使用支付宝打赏</b>
            </span>
            <span class="wechat-code">
              <div class="code-image"></div>
              <b>使用微信打赏</b>
            </span>
          </span>
        </div>
        <p class="notice">点击上方按钮,请我喝杯咖啡！</p>
      </div>
    
    <!-- 打赏 END -->
    <!-- 二维码 START -->
    
      <div class="qrcode">
        <canvas id="share-qrcode"></canvas>
        <p class="notice">扫描二维码，分享此文章</p>
      </div>
    
    <!-- 二维码 END -->
    
      <!-- Gitment START -->
      <div id="comments"></div>
      <!-- Gitment END -->
    
  </article>
  <!-- Article END -->
  <!-- Catalog START -->
  
    <aside class="catalog-container">
  <div class="toc-main">
  <!-- 不蒜子统计 -->
    <strong class="toc-title">目录</strong>
    
      <ol class="toc-nav"><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#课程表分析"><span class="toc-nav-text">课程表分析</span></a></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#免费课案例"><span class="toc-nav-text">免费课案例</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-5"><a class="toc-nav-link" href="#创建models：course-models-py"><span class="toc-nav-text">创建models：course&#x2F;models.py</span></a></li><li class="toc-nav-item toc-nav-level-5"><a class="toc-nav-link" href="#注册models：course-adminx-py"><span class="toc-nav-text">注册models：course&#x2F;adminx.py</span></a></li><li class="toc-nav-item toc-nav-level-5"><a class="toc-nav-link" href="#数据库迁移"><span class="toc-nav-text">数据库迁移</span></a></li></ol></li></ol></li></ol></li></ol>
    
  </div>
</aside>
  
  <!-- Catalog END -->
</main>

<script>
  (function () {
    var url = 'http://www.liuqingzheng.top/python/路飞项目/6-课程模块/2-课程主页之课程表分析/';
    var banner = ''
    if (banner !== '' && banner !== 'undefined' && banner !== 'null') {
      $('#article-banner').css({
        'background-image': 'url(' + banner + ')'
      })
    } else {
      $('#article-banner').geopattern(url)
    }
    $('.header').removeClass('fixed-header')

    // error image
    $(".markdown-content img").on('error', function() {
      $(this).attr('src', 'http://file.muyutech.com/error-img.png')
      $(this).css({
        'cursor': 'default'
      })
    })

    // zoom image
    $(".markdown-content img").on('click', function() {
      var src = $(this).attr('src')
      if (src !== 'http://file.muyutech.com/error-img.png') {
        var imageW = $(this).width()
        var imageH = $(this).height()

        var zoom = ($(window).width() * 0.95 / imageW).toFixed(2)
        zoom = zoom < 1 ? 1 : zoom
        zoom = zoom > 2 ? 2 : zoom
        var transY = (($(window).height() - imageH) / 2).toFixed(2)

        $('body').append('<div class="image-view-wrap"><div class="image-view-inner"><img src="'+ src +'" /></div></div>')
        $('.image-view-wrap').addClass('wrap-active')
        $('.image-view-wrap img').css({
          'width': `${imageW}`,
          'transform': `translate3d(0, ${transY}px, 0) scale3d(${zoom}, ${zoom}, 1)`
        })
        $('html').css('overflow', 'hidden')

        $('.image-view-wrap').on('click', function() {
          $(this).remove()
          $('html').attr('style', '')
        })
      }
    })
  })();
</script>


  <script>
    var qr = new QRious({
      element: document.getElementById('share-qrcode'),
      value: document.location.href
    });
  </script>



  <script>
    var gitmentConfig = "liuqingzheng";
    if (gitmentConfig !== 'undefined') {
      var gitment = new Gitment({
        id: "python/路飞项目/6-课程模块/2-课程主页之课程表分析",
        owner: "liuqingzheng",
        repo: "FuckBlog",
        oauth: {
          client_id: "32a4076431cf39d0ecea",
          client_secret: "94484bd79b3346a949acb2fda3c8a76ce16990c6"
        },
        theme: {
          render(state, instance) {
            const container = document.createElement('div')
            container.lang = "en-US"
            container.className = 'gitment-container gitment-root-container'
            container.appendChild(instance.renderHeader(state, instance))
            container.appendChild(instance.renderEditor(state, instance))
            container.appendChild(instance.renderComments(state, instance))
            container.appendChild(instance.renderFooter(state, instance))
            return container;
          }
        }
      })
      gitment.render(document.getElementById('comments'))
    }
  </script>




    <div class="scroll-top">
  <span class="arrow-icon"></span>
</div>
    <footer class="app-footer">
<!-- 不蒜子统计 -->
<span id="busuanzi_container_site_pv">
     本站总访问量<span id="busuanzi_value_site_pv"></span>次
</span>
<span class="post-meta-divider">|</span>
<span id="busuanzi_container_site_uv" style='display:none'>
     本站访客数<span id="busuanzi_value_site_uv"></span>人
</span>
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>



  <p class="copyright">
    &copy; 2021 | Proudly powered by <a href="https://www.cnblogs.com/xiaoyuanqujing" target="_blank">小猿取经</a>
    <br>
    Theme by <a href="https://www.cnblogs.com/xiaoyuanqujing" target="_blank" rel="noopener">小猿取经</a>
  </p>
</footer>

<script>
  function async(u, c) {
    var d = document, t = 'script',
      o = d.createElement(t),
      s = d.getElementsByTagName(t)[0];
    o.src = u;
    if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
    s.parentNode.insertBefore(o, s);
  }
</script>
<script>
  async("//cdnjs.cloudflare.com/ajax/libs/fastclick/1.0.6/fastclick.min.js", function(){
    FastClick.attach(document.body);
  })
</script>

<script>
  var hasLine = 'true';
  async("//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js", function(){
    $('figure pre').each(function(i, block) {
      var figure = $(this).parents('figure');
      if (hasLine === 'false') {
        figure.find('.gutter').hide();
      }
      var lang = figure.attr('class').split(' ')[1] || 'code';
      var codeHtml = $(this).html();
      var codeTag = document.createElement('code');
      codeTag.className = lang;
      codeTag.innerHTML = codeHtml;
      $(this).attr('class', '').empty().html(codeTag);
      figure.attr('data-lang', lang.toUpperCase());
      hljs.highlightBlock(block);
    });
  })
</script>





<!-- Baidu Tongji -->

<script>
    var _baId = 'c5fd96eee1193585be191f318c3fa725';
    // Originial
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?" + _baId;
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
</script>


<script src="/js/script.js"></script>


<script src="/js/search.js"></script>


<script src="/js/load.js"></script>



  <span class="local-search local-search-google local-search-plugin" style="right: 50px;top: 70px;;position:absolute;z-index:2;">
      <input type="search" placeholder="站内搜索" id="local-search-input" class="local-search-input-cls" style="">
      <div id="local-search-result" class="local-search-result-cls"></div>
  </span>


  </body>
</html>